﻿using ImoviesBlazor.Server.Data;
using ImoviesBlazor.Shared.Entities;

namespace ImoviesBlazor.Server.Repository
{
    public class AnimationVlinkRepository : IAnimationVlinkRepository
    {
        private readonly ApplicationDbContext _dbContext;

        public AnimationVlinkRepository(ApplicationDbContext dbContext)
        {
            this._dbContext = dbContext;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="animationVlink"></param>
        public void AddAnimationVlink(AnimationVlink animationVlink)
        {
            _dbContext.Set<AnimationVlink>().Add(animationVlink);
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="animationVlinks"></param>
        /// <returns></returns>
        public async Task BatchAddMovieVlink(IEnumerable<AnimationVlink> animationVlinks)
        {
            await _dbContext.Set<AnimationVlink>().AddRangeAsync(animationVlinks);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="animationVlinkId"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task DeleteAnimationVlink(uint animationVlinkId)
        {
            var t = await _dbContext.Set<AnimationVlink>().FindAsync(animationVlinkId);
            if (t != null)
            {
                _dbContext.Set<AnimationVlink>().Remove(t);
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="animationVlink"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void UpdateAnimationVlink(AnimationVlink animationVlink)
        {
            _dbContext.Set<AnimationVlink>().Update(animationVlink);
        }


        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        public Task<bool> SaveAsync()
        {
            return Task.FromResult(_dbContext.SaveChanges() > 0);
        }

    }
}
